//
//  BaseRefreshController.h
//  Postre
//
//  Created by CoderLT on 2017/5/24.
//  Copyright © 2017年 CoderLT. All rights reserved.
//

#import "BaseController.h"
#import <MJRefresh/MJRefresh.h>
#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
#import "ATRefreshModel.h"

/**
 *  集成刷新控件
 */
typedef NS_ENUM(NSUInteger, ATRefreshOption) {
    ATRefreshNone = 0,
    ATHeaderRefresh = 1 << 0,
    ATFooterRefresh = 1 << 1,
    ATHeaderAutoRefresh = 1 << 2,
    ATFooterAutoRefresh = 1 << 3,
    ATFooterDefaultHidden = 1 << 4,
    ATHeaderAutoRefreshVisible = 1 << 5,
    ATFooterAutoRefreshVisible = 1 << 6,
    ATRefreshDefault = (ATHeaderRefresh | ATHeaderAutoRefresh | ATFooterRefresh | ATFooterDefaultHidden),
};
#define RefreshPageStart (1)
#define RefreshPageSize (10)
#define RefreshSizeHasMore (RefreshPageSize/2)

@interface BaseRefreshController : BaseController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (nonatomic, weak, readonly) UIScrollView *scrollView;
@property (nonatomic, assign, readonly) NSInteger currentPage;
@property (nonatomic, assign, readonly) BOOL isRefreshing;
@property (nonatomic, strong) NSDate *lastRefreshDate;


/**
 自动设置刷新时机 界面会自动调用 [self reloadData] 或者 [self.scrollView reloadData]
 */
@property (nonatomic, assign) BOOL refreshFormBackground;
@property (nonatomic, strong) NSDate *appDidEnterBackgroundDate;
- (void)applicationDidEnterBackground;
- (void)applicationWillEnterBackground:(NSDate *)enterDate;

/**
 自动设置刷新时机 界面会自动调用 headerRefreshing
 */
@property (nonatomic, assign) BOOL refreshWillAppear;
@property (nonatomic, assign) BOOL refreshDidAppear;
@property (nonatomic, assign) BOOL refreshWillAppearIfFirstPage;
@property (nonatomic, assign) BOOL refreshDidAppearIfFirstPage;
- (BOOL)isAtFirstPage;

/**
 设置刷新控件 子类可在refreshData中发起网络请求, 请求结束后回调endRefresh结束刷新动作
 
 scrollView 刷新控件所在scrollView
 option 刷新空间样式
 */
- (void)setupRefresh:(UIScrollView *)scrollView option:(ATRefreshOption)option;
- (void)headerRefreshing NS_REQUIRES_SUPER;
- (void)footerRefreshing NS_REQUIRES_SUPER;
- (void)refreshData:(NSInteger)page;
- (void)endRefresh:(BOOL)hasMore;
- (void)endRefreshNeedHidden:(BOOL)hasMore;
- (void)endRefreshFailure;
- (void)scroolToTopBeginRefresh;

/**
 设置空界面显示, 如果需要定制化 请实现协议 DZNEmptyDataSetSource, DZNEmptyDataSetDelegate
 tableView或者CollectionView数据reload后, 空界面展示可自动触发, 如需强制刷新, 请调用 [scrollView reloadEmptyDataSet];
 
 scrollView 空界面所在scrollView
 image 空界面图片
 title 空界面标题
 */
- (void)setupEmpty:(UIScrollView *)scrollView image:(UIImage *)image title:(NSString *)title;
- (void)setupEmpty:(UIScrollView *)scrollView;
@end
